<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/backstage/cl/common/wechatLibs.jsp"%>
<!doctype html>
<html>
<head>
    <title>兑换颜值</title>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    
    <style>
        html,body{
            background:#f7f7f7;
        }
    </style>
    <jsp:include page="/WEB-INF/backstage/util.jsp"></jsp:include>
</head>
<body>
<a href="/bsc/wechat/GomyBeauty">返回</a>  
    <div class="my-exchange-coin">
        <p class="tel">绑定手机号：${user.mobile}</p><button type="button" class="btn btn-info btn-lg" w onclick="fun(${user.mobile})"  >查看兑换码</button>
        <input class="input-text" type="text"  id="cdkey" placeholder="请输入兑换码">
        <div class="btn">
            <a href="#" onclick="saveExchangeBeauty()">确定</a>
        </div>
    </div>
    
    
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width: 50%">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">兑换码</h4>
				</div>
				<div class="modal-body">
					<div id="div">
					</div>
				</div>
			</div>
		</div>
	</div>    
    
</body>
<script type="text/javascript">
/**
 * 获取验证码
 */
function fun(mobile) {
	$.ajax({
		type : 'post',
		url : '/bsc/wechat/cdkey',
		data : {
			mobile:mobile
		},
		dataType : 'json',
		success : function(data) {
			if (data.length==0) {
				alert("暂无兑换码");
			}else{
				var div=$("#div");
				var span="";
				$.each(data,function(index,a){
					span+="<input type='text' value='"+a.cdkey+"' readonly='readonly'/>";
				});
				div.append(span);
				$("#myModal").modal("show");
			}
		}
	})
}
 
 
/**
 * 兑换颜值
 */
 function saveExchangeBeauty(){
	 var toast = new auiToast();
	  var cdkey = $("#cdkey").val();
		if (cdkey== '') {
			toast.fail({
				title : "请输入兑换码",
				duration : 2000
			});
			return;
	 }
		toast.loading({
            title:"数据处理中"
           
        })
		$.ajax({
			type : 'post',
			url : '/bsc/wechat/Beauty',
			data : {
				mobile:'${user.mobile}',
				cdkey:cdkey
			},
			dataType : 'json',
			success : function(data) {
				alert(data)
				if (data) {
					if (data== "1") {
						toast.success({
						    title:data.appmsg,
						    duration:2000
						});
						window.location.href ='/bsc/wechat/Gohome';
					} else if(data== "2") {
						toast.fail({
							title : "已兑换",
							duration : 2000
						});
					}else if(data== "3") {
						toast.fail({
							title : "已过期",
							duration : 2000
						});
					}else{
						toast.fail({
							title : "请输入正确的兑换码",
							duration : 2000
						});
					}
				} else {
					toast.fail({
						title : "兑换失败，系统处理异常",
						duration : 2000
					});
				}
			},
			error : function() {
				toast.fail({
					title : "网络异常",
					duration : 2000
				});
			}
		})
		toast.hide();
 }
</script>
</html>